package com.lihaogn.sell.web;

import com.lihaogn.sell.entity.Order;
import com.lihaogn.sell.service.OrderService;
import com.lihaogn.sell.vo.ListVo;
import com.lihaogn.sell.vo.OrderDetailVo;
import com.lihaogn.sell.vo.OrderVo;
import com.lihaogn.sell.vo.SearchPageVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @FileName: OrderController
 * @Description: TODO
 * @Author: lihao
 * @Date: 2019-05-17 14:32
 * @Version: 1.0
 */
@Controller
@Api(tags = "订单数据接口")
public class OrderController {

    @Autowired
    private OrderService orderService;


    @Autowired
    private ListVo listVo;

    private String orderId;

    // ======================= 访问 =======================

    @ApiIgnore
    @RequestMapping(value = "/orderDetail")
    private String orderDetail(String orderId) {
        this.orderId = orderId;
        System.out.println(orderId);
        return "order/orderDetail-list";
    }

    @ApiIgnore
    @RequestMapping(value = "/orderShow")
    private String orderShow() {
        return "order/order-list";
    }

    // ======================= 操作 =======================

    // ========== 查询 ==========

    @GetMapping(value = "/orderSearch")
    @ResponseBody
    private ListVo orderSearch(SearchPageVo searchPageVo) {
        return orderService.getOrderByCondition(searchPageVo);
    }

    @GetMapping(value = "/showAllOrder")
    @ResponseBody
    private ListVo showAllOrder(String page, String limit) {
        List<OrderVo> orderList = orderService.getAllOrder(page,limit);

        listVo.setCode(0);
        listVo.setMsg("success");
        listVo.setCount(orderService.getAllRowCount());
        listVo.setData(orderList);

        return listVo;
    }

    @GetMapping(value = "/showOrderDetail")
    @ResponseBody
    private ListVo showOrderDetail() {
        List<OrderDetailVo> orderDetailList = orderService.getOrderDetailById(orderId);

        listVo.setCode(0);
        listVo.setMsg("success");
        listVo.setCount(orderDetailList.size());
        listVo.setData(orderDetailList);

        return listVo;

    }

    // ========== 增加 ==========

    @PostMapping(value = "/addOneOrder")
    @ResponseBody
    private Integer addOneOrder(Order order) {
        int i = orderService.addOneOrder(order);
        return i;
    }

    // ========== 更新 ==========

    @PutMapping(value = "/changeOrderPayStatus")
    @ResponseBody
    private Integer changeOrderPayStatus(String orderId) {

        int i = orderService.changeOrderPayStatus(orderId);
        return i;
    }

    // ========== 删除 ==========

    @DeleteMapping(value = "/deleteOneOrder")
    @ResponseBody
    private Integer deleteOneOrder(String orderId) {
        int i = orderService.deleteOneOrder(orderId);
        return i;
    }

    @DeleteMapping(value = "/deleteMultiOrder")
    @ResponseBody
    private Integer deleteMultiOrder(HttpServletRequest request) {
        return orderService.deleteMultiOrder(request);
    }

}
